package com.ruoyi.common.constant;

import com.ruoyi.common.utils.StringUtils;
import org.apache.poi.hssf.record.NameRecord;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * 通用常量信息
 *
 * @author ruoyi
 */
public class Constants
{
    /**
     * UTF-8 字符集
     */
    public static final String UTF8 = "UTF-8";

    /**
     * GBK 字符集
     */
    public static final String GBK = "GBK";

    /**
     * 通用成功标识
     */
    public static final String SUCCESS = "0";

    /**
     * 通用失败标识
     */
    public static final String FAIL = "1";

    /**
     * 登录成功
     */
    public static final String LOGIN_SUCCESS = "Success";

    /**
     * 注销
     */
    public static final String LOGOUT = "Logout";

    /**
     * 注册
     */
    public static final String REGISTER = "Register";

    /**
     * 登录失败
     */
    public static final String LOGIN_FAIL = "Error";

    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String IS_ASC = "isAsc";

    /**
     * 系统用户授权缓存
     */
    public static final String SYS_AUTH_CACHE = "sys-authCache";

    /**
     * 参数管理 cache name
     */
    public static final String SYS_CONFIG_CACHE = "sys-config";

    /**
     * 参数管理 cache key
     */
    public static final String SYS_CONFIG_KEY = "sys_config:";

    /**
     * 字典管理 cache name
     */
    public static final String SYS_DICT_CACHE = "sys-dict";

    /**
     * 字典管理 cache key
     */
    public static final String SYS_DICT_KEY = "sys_dict:";

    /**
     * 资源映射路径 前缀
     */
    public static final String RESOURCE_PREFIX = "/profile";


    private static BASE64Decoder decoder = new BASE64Decoder();
    private static BASE64Encoder encoder = new BASE64Encoder();


    /*解码*/
    public static String getDecoder(String str){
        if(StringUtils.isEmpty(str)){
            return null;
        }
        String decoderStr;
        try {
            decoderStr =  new String(decoder.decodeBuffer(str),Constants.UTF8);
        } catch (IOException e) {
            return null;
        }
        return decoderStr;
    }



    /*编码*/
    public static String getEncoder(String str){
        if(StringUtils.isEmpty(str)){
            return null;
        }
        String encoderStr;
        try {
            byte[] bytes = str.getBytes(Constants.UTF8);
            encoderStr  = encoder.encode(bytes);
        } catch (UnsupportedEncodingException e) {
            return null;
        }
        return encoderStr;
    }


    /**
     * 状态常亮
     */
    public static class StrStatusUtils{

        public static final String zero = "0";
        public static final String one = "1";
        public static final String two = "2";
        public static final String three = "3";
        public static final String four = "4";
        public static final String null_k = "";
    }

    public static class LongStatusUtils{
        public static final  Long zero = 0L;
        public static final  Long one = 1L;
        public static final  Long two = 2L;
        public static final  Long three = 3L;
        public static final  Long four = 4L;


    }

    public static class IntegerStatusUtils{
        public static final  Integer zero = 0;
        public static final  Integer one = 1;
        public static final  Integer two = 2;
        public static final  Integer three = 3;
        public static final  Integer four = 4;

    }


    /*public static class tableName{

        *//*漫画表前缀*//*
        public static final String MH_NAME = "mhname";

        *//*漫画 篇章*//*
        public static final String MH_CHAPTER = "mhChapter";
        *//*漫画 篇章页数*//*
        public static final String MH_PAGE = "mhpage";



        *//*redis存储是 时间限制 还是永不过期，true是有时间显示*//*
        public static final boolean BOOL_SWITCH = true;

        *//*redis初始过期时间 五天 一个小时*//*
        public static final Long time = 435600L;

    }*/

    public static class mysqlOrder{
        /*desc降序*/
        public static final String desc = "desc";

        /*asc升序*/
        public static final String asc = "asc";
    }


}
